<?php
/*
 * @Description    : 验证
 * @Version        : 1.0.0
 * @Author         : QianLong
 * @Date           : 2021-04-16 16:48:24
 * @LastEditors    : QianLong
 * @LastEditTime   : 2022-07-01 17:18:22
 */

namespace app\common;

use app\api\model\SysSetting;
use app\common\service\DragonCaptcha;
use app\lib\exception\ApiException;

class Verify
{
  public static function check(array $data)
  {
    $checkSetting = SysSetting::where('id', 1)->find();
    if ($checkSetting['captcha_type'] == 'dragon') {
      self::Dragon($data, $checkSetting);
    }
  }
  private static function Dragon(array $data, $config)
  {
    if (!isset($data['token'])) {
      throw new ApiException('请先进行安全验证');
    }
    $dragon = new DragonCaptcha($config);
    $dataVerify['token'] = $data['token'];
    $ypResult = $dragon->check($dataVerify,$config['dragon_captcha_id'],$config['dragon_secret_key']);
    if ($ypResult['code'] != 200) {
      throw new ApiException('验证失败，请刷新页面后重新验证');
    }
  }
}